﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using MLSMooc.BO;
using MLSMooc.DAO.Implement.Feedback;
using MLSMooc.Helper;
using MLSMooc.Service.Implement.Feedback;

namespace MLSMooc.Controllers
{
    public class FeedbackController : Controller
    {
        FeedbackDAO feedbackDAO = FeedbackDAO.Getinstance();
        FeedbackServiceImpl feeservice = FeedbackServiceImpl.Getinstance();

        [HttpGet]
        public async Task<string> GetByIdFeeInfo(int id)
        {
            var res = await feedbackDAO.GetByIdFeeInfo(id);
            return SerializeHelper.SerializeJson(res);
        }

        [HttpPost]
        public async Task<int> InsertFeedback(FeedbackBO data)
        {
            var list = await feedbackDAO.GetByIdAndAdminIdexist(data.ProId,data.AdminId);
            if (list.Count()>0 && data.AdminId!=1)
            {
                return -1;
            }
            else {
                var res = await feeservice.InsertFeedback(data);
                return res;
            }
            
           
        }

        [HttpPost]
        public async Task<int> DeleteFeedback(int id)
        {
            var res = await feeservice.DeleteFeedback(id);
            return res;
        }
    }
}